<?php

namespace mpend\modules\shop\models;

use Yii;
use common\helpers\Url;

/**
 * 标准化产品单元数据模型（SPU）
 * 
 * @author emhome<emhome@163.com>
 * @since 2.0
 */
class StandardProductUnit extends \common\models\shop\ShopProduct {

    /**
     * 关联商品规格
     * @return \yii\db\ActiveQueryInterfac the relational query object.
     */
    public function getSpecs() {
        return $this->hasMany(\common\models\views\ViewSkuSpecMp::className(), ['product_id' => 'id'])->active();
    }

    /**
     * 关联商品规格
     * @return \yii\db\ActiveQueryInterfac the relational query object.
     */
    public function getGoods() {
        return $this->hasMany(StockKeepingUnit::className(), ['product_id' => 'id'])->active(StockKeepingUnit::STATUS_ACTIVE);
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'name',
            'picture' => function() {
                return Url::attach($this->cover);
            },
            'price',
            'origin' => function() {
                return '';
            },
            'slogan',
            'description',
            'express' => function() {
                return true;
            },
            'content' => 'detail',
            'album',
            'sales',
            'collected',
            'shareData',
        ];
    }

}
